<script setup>
import { onMounted, ref } from 'vue'
import * as echarts from 'echarts'

const charts = ref()

onMounted(() => {
  let myCharts = echarts.init(charts.value)
  let option = {
    title: {
      text: '本日总数',
      left: 130,
      top: 'center',
      textStyle: {
        fontSize: 16,
        fontWeight: 400,
        color: '#fff'
      },
      textAlign: 'center'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: 40,
      right: 20,
      orient: 'vertical', // 图例组件方向设置
      textStyle: {
        color: 'white'
      },
      itemWidth: 16,
      itemHeight: 16
    },
    series: [
      {
        name: '年龄比例',
        type: 'pie',
        radius: ['35%', '70%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10
        },
        label: {
          show: true,
          position: 'inside',
          color: 'white',
          z:3
        },
        data: [
          { value: 16, name: '10岁以下' },
          { value: 8, name: '10-18岁' },
          { value: 12, name: '18-30岁' },
          { value: 24, name: '30-40岁' },
          { value: 20, name: '40-60岁' },
          { value: 20, name: '60岁以上' },
        ],
        labelLine: {
          show: false
        },
        left: -150
      }
    ],
    // 调整图形图表的位置
    grid: {
      left: 0,
      top: 0,
      right: 0,
      bottom: 0
    }
  }
  myCharts.setOption(option)
})
</script>

<template>
  <div class="box2">
    <div class="title">
      <p>年龄比例</p>
      <img src="../../images/dataScreen-title.png" alt="">
    </div>
    <div class="charts" ref="charts">

    </div>
  </div>
</template>

<style scoped lang="less">
.box2 {
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-lb.png) no-repeat;
  background-size: 100% 90%;
  .title {
    p {
      color: white;
      font-size: 16px;
      margin-bottom: 8px;
    }
  }
  .charts {
    height: 260px;
  }
}
</style>
